package com.newlink.building.views

import android.app.AlertDialog
import android.content.Context
import android.view.LayoutInflater
import androidx.lifecycle.ViewModel
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.newlink.building.R
import com.newlink.building.adapter.OptionItem
import com.newlink.building.adapter.SingleChoiceAdapter
import org.linphone.core.AudioDevice

/**
 * @Author: Jake
 * @Date: 2024-06-27
 * @Description:
 */
class Module_Phone_SingleChoiceDialog(val context: Context, viewModel: ViewModel) {
    fun show(options: List<OptionItem>, onOptionSelected: (OptionItem) -> Unit) {

        val inflater = LayoutInflater.from(context)
        val dialogView = inflater.inflate(R.layout.dialog_recycler_view, null)
        val recyclerView: RecyclerView = dialogView.findViewById(R.id.recycler_view)

        val dialog = AlertDialog.Builder(context)
            .setView(dialogView)
            .setTitle("选择音频通道")
            .create()

        recyclerView.layoutManager = GridLayoutManager(context, 2)
        recyclerView.adapter =
            SingleChoiceAdapter(options, AudioDevice.Type.Speaker) { selectedOption ->
                onOptionSelected(selectedOption)
                dialog.dismiss()
            }

        dialog.show()
    }
}